﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;
using Yto.Common.Extensions;

namespace Yto.AutoMapper.Attributes
{
    public class AutoMapFromAttribute : BaseMapAttribute
    {
        public MemberList MemberList { get; set; } = MemberList.Destination;

        public AutoMapFromAttribute(params Type[] targetTypes) : base(targetTypes) { }

        public AutoMapFromAttribute(MemberList memberList,params Type[] targetTypes) : base(targetTypes)
        {
            MemberList = memberList;
        }


        public override void CreateMap(IMapperConfigurationExpression configurationExpression, Type type)
        {
            if (TargetTypes.IsNullOrEmpty())
            {
                return;
            }

            foreach(var item in TargetTypes)
            {
                configurationExpression.CreateMap(item, type, MemberList.Destination);
            }
        }
    }
}
